
-- Client Events
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
    function()
		showCursor(false)
		outputChatBox("-DebugServ- Loaded account.lua")
		
		-- Preloading LOGIN
	    WindowLogin = guiCreateWindow(0.375, 0.715, 0.25, 0.25, "GreenHood Login", true)
        
        guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Username:", true, WindowLogin)
        guiCreateLabel(0.0825, 0.5, 0.25, 0.25, "Password:", true, WindowLogin)
        
        UserName = guiCreateEdit(0.415, 0.2, 0.5, 0.15, getPlayerName(getLocalPlayer()), true, WindowLogin)
        PassWord = guiCreateEdit(0.415, 0.5, 0.5, 0.15, "", true, WindowLogin)
		
        guiEditSetMaxLength(UserName, 12)
        guiEditSetMaxLength(PassWord, 10)
        guiEditSetReadOnly(UserName, true)
		
        loginButton = guiCreateButton(0.415, 0.7, 0.25, 0.2, "Log In", true, WindowLogin)
        
        guiSetVisible(WindowLogin, false)
		guiWindowSetSizable(WindowLogin, false)
		guiWindowSetMovable(WindowLogin, false)

		-- Preloading REGISTER
	    WindowRegister = guiCreateWindow(0.375, 0.715, 0.25, 0.25, "GreenHood register", true)

	    guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Username:", true, WindowRegister)
	    guiCreateLabel(0.0825, 0.4, 0.25, 0.25, "Password:", true, WindowRegister)
	    guiCreateLabel(0.0825, 0.6, 0.25, 0.25, "Email:", true, WindowRegister)
	        
	    Regusername = guiCreateEdit(0.415, 0.2, 0.5, 0.15, getPlayerName(getLocalPlayer()), true, WindowRegister)
	    Regpassword = guiCreateEdit(0.415, 0.4, 0.5, 0.15, "", true, WindowRegister)
	    Regemail = guiCreateEdit(0.415, 0.6, 0.5, 0.15, "", true, WindowRegister)
			
	    guiEditSetMaxLength(Regusername, 12)
	    guiEditSetMaxLength(Regpassword, 10)
	    guiEditSetMaxLength(Regemail, 50)
	    guiEditSetReadOnly(Regusername, true)
			
	    registerButton = guiCreateButton(0.415, 0.8, 0.25, 0.2, "Register", true, WindowRegister)
	        
	    guiSetVisible(WindowRegister, false)
		guiWindowSetSizable(WindowRegister, false)
		guiWindowSetMovable(WindowRegister, false)
	end
)

addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()),
	function()
	    if source == loginButton then
			triggerServerEvent("checkAccount", getRootElement(), guiGetText(UserName), guiGetText(PassWord))
		elseif source == registerButton then
			triggerServerEvent("checkRegister", getRootElement(), guiGetText(Regusername), guiGetText(Regpassword), guiGetText(Regemail))
		end
	end
)

-- Client commands


-- Client functions


-- Client custom events

addEvent("toggleLoginScreen", true)
addEventHandler("toggleLoginScreen", getRootElement(),
	function()
		outputChatBox("-NickServ- Please login!")
		guiSetVisible(WindowLogin, true)
		setElementAlpha(WindowLogin, 1)
		showCursor(true)
		guiSetInputEnabled(true)
	end
)

addEvent("toggleRegisterScreen", true)
addEventHandler("toggleRegisterScreen", getRootElement(),
	function()
		outputChatBox("-NickServ- Please register!")
		guiSetVisible(WindowRegister, true)
		setElementAlpha(WindowRegister, 1)
		showCursor(true)
		guiSetInputEnabled(true)
	end
)

addEvent("hideRegisterScreen", true)
addEventHandler("hideRegisterScreen", getRootElement(),
	function()
		guiSetVisible(WindowRegister, false)
		showCursor(false)
		guiSetInputEnabled(false)
	end
)

addEvent("hideLoginScreen", true)
addEventHandler("hideLoginScreen", getRootElement(),
	function()
		guiSetVisible(WindowLogin, false)
		showCursor(false)
		guiSetInputEnabled(false)
	end
)